<?php
/**
 * This is the template for action id `view`.
 */

/** @var yii\web\View $this */
/** @var \console\gii\controller\Generator $generator */
/** @var string $actionCamelID */
/** @var string $modelName */
$modelName = $generator->modelName;
?>
        $table = TableBuilder::instance(['id' => 'BID_<?= $generator->controllerCamelID . '_' . $actionCamelID ?>']);
        if ($this->isAjax) {
            $table->setQuery(function () {
                $dbQuery = <?= $modelName ?>::query();

                $queryParams = $this->filteredGet;
                [$startAt, $endAt] = T::rangeDateSplit($queryParams['created_at'] ?? null);
                $dbQuery->andFilterWhere([
                    'and',
                    // 创建日期
                    ['between', 'created_at', $startAt, $endAt],
                ]);

                return $dbQuery;
            })->setOrderBy([
                'created_at' => SORT_DESC,
            ])->setColumns([
                'id',
                'created_at',
                'updated_at',
            ]);
        } else {
            $t = date('t');
            App::setViewBreadcrumb([
                ['name' => '父站位'],
                ['name' => '<?= $generator->sourceName ?>列表', 'url' => '<?= $generator->controllerID ?>/index']
            ]);
            $table->setTitle('<?= $generator->sourceName ?>列表')
                ->setMaxHeight(750)
                ->setLimit(10)
                ->setTableHead([
                    $this->tableHead->field('id')->title('ID'),
                    $this->tableHead->field('created_at')->title('添加时间')->minWidth(150),
                    $this->tableHead->field('updated_at')->title('上次更新')->minWidth(150),
                    $this->tableHead->toolbar()->title('操作')->fixedNone(),
                ])
                ->setToolbarCustom([
                    $this->toolbarCustom->modal()->title('新 增')->route('<?= $generator->controllerID ?>/create'),
                ])
                ->setRowOperation([
                    $this->rowOperation->modal()->title('编 辑')->route('<?= $generator->controllerID ?>/update'),
                ])
                ->setToolbarRefresh()
                ->setToolbarFilter([
                    'created_at' => $this->toolbarFilter->datetime()->label('创建日期')->placeholder('请选择')->uiClass('w-auto float-none')->style('width:280px;')->quickChoice(['昨日' => T::createRangeDate('-1 day', '-1 day'), '近3日' => T::createRangeDate('-2 days'), '近7日' => T::createRangeDate('-6 days'), '近'.$t.'日' => T::createRangeDate('-'.($t-1).' days')]),
                    //'keyword' => $this->toolbarFilter->text()->label('关键词')->uiClass(['w-md-300']),
                    //'sort' => $this->toolbarFilter->select()->label('排 序')->options([SORT_DESC => '降序', SORT_ASC => '升序'])->uiConfig('minimumResultsForSearch', -1)->uiClass(['w-md-300']),
                ]);
        }

        return $table->render();
